import requests
import json
import string
import random
import pymysql
from auto_interface.parameter_case.login_parameter import Login_par

#测试数据（耗料单）
data = {}

#生产数据
# data = {"id":"241","orgId":"103061","consumptionNo":"103061MU210329000241","contractNo":"","optStatus":"1","chgTmsCnt":"0","businessTypecd":"3","bizopEtpsNm":"测试企业","bizopEtpsNo":"2249S00001","bizopEtpsSccd":"12345678901234567W","passportUsedTypecd":"1","dclData":"","dclTypecd":"1","isChange":"0","businessDeclareNo":"","rmk":"测试数据","masterCuscd":"2249","createTime":"","endTime":"","consumDt":"consumDt_1","produceDt":"produceDt_1","materialUseStatus":[{"id":"2361","pid":"241","createTime":"2021-11-22 21:20:17","optStatus":"1","optUserName":"tester001","optTime":"2021-11-22 21:20:17","remark":"暂存成功","fileName":""},{"id":"261","pid":"241","createTime":"2021-03-29 15:46:26","optStatus":"1","optUserName":"tester001","optTime":"2021-03-29 15:46:26","remark":"暂存成功","fileName":""}],"workOrder":[]}
# global data
consumDt = {}

produceDt = [{}]

class request_test():
    global data1
    data1 = json.dumps(data)

    def post_requests(self, for_num):
        #测试环境
        token = ''
        url = ''

        #生产环境
        # token = ''
        # url = ''

        status = '1'
        self.consumDt_2 = []

        while status == '1':
            i = 0
            while i < for_num:
                consumDt_0 = {}
                consumDt.update({"gdsMtno": ''.join(random.sample(string.ascii_letters + string.digits, 8))})
                consumDt_0.update(consumDt)
                self.consumDt_2.append(consumDt_0)
                i += 1

            data = data1.replace("consumDt_1", json.dumps(self.consumDt_2)).replace("produceDt_1", json.dumps(produceDt * for_num)).replace('"[', '[').replace(']"', ']')

            print("=================1===================")
            try:
                headers = {"orgId": "103625", "Content-Type": "application/json", "epToken": "%s" % token}
                response = requests.post(url=url, headers=headers, data=data)
                status = response.json().get("status")
                ass_value = response.json()

                if status == "1" and response.json().get("note") == '暂存成功！':
                    print(response.json().get("note"))
                    break
                elif 'token cather user fail' in str(ass_value):
                    print("当前最大支持表体数：%s" % (for_num-1))
                else:
                    status = 0
                    print(ass_value)
                    print("当前最大支持表体数：%s" % (for_num-1))
            except Exception as E:
                print("当前最大支持表体数：%s" % (for_num-1))
                print(E)
                return False, E, "请求异常"
            for_num += 1
            print(for_num)


request_test().post_requests(60)
